////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.foreignexchange;

import android.os.Bundle;
import android.text.Html;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Http.H_CODE;
import cc.telecomdigital.tdstock.Http.HttpSuperClassStockBaseActivity;
import cc.telecomdigital.tdstock.Http.Services.HttpAppInfo;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.H_UserClient_HttpRequest_Result;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.groups.ForeignExchangeGroup;

/**
 * @author haibo
 */
public class EconomicCalendarContentActivity extends HttpSuperClassStockBaseActivity
{
	protected static final String	TAG		= EconomicCalendarContentActivity.class.getSimpleName();

	private TextView				_txt;
	private TextView				_titleTextView;
	private Button					_toolBtnReturn;
	static public int				iTypeId	= 0;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.economic_calendar_content);

		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		_toolBtnReturn.setFocusable(true);
		_toolBtnReturn.setClickable(true);
		_toolBtnReturn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "close current activity and forwarding to the previous");

//				Intent intent = new Intent(getApplicationContext(), _cls);
//				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
//				SwitchForwardActivity(_cls, intent);
				
				SwitchBackActivity();
			}
		});

		_txt = (TextView) findViewById(R.id.list_item_content);
		// _txt.setAutoLinkMask(Linkify.ALL);
		_txt.setAutoLinkMask(Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
		_titleTextView = (TextView) findViewById(R.id.more_menu_item_title);
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		updateTitle();

		// _txt.setText(Html.fromHtml(_content.replaceAll("[\n\r]",
		// "<br>").replaceAll("&lt;", "<").replaceAll("&gt;", ">")));
	}

	private void updateTitle()
	{
		String title = ((ITDLApplication) getApplicationContext()).getString(CommonDefn.TOP_BAR_TITLE);
		if (_titleTextView != null && title != null)
			_titleTextView.setText(title);
	}

	private void updateData(String iContent)
	{
		_txt.setText(Html.fromHtml(iContent.replaceAll("[\n\r]", "<br>").replaceAll("&lt;", "<").replaceAll("&gt;", ">")));
	}
	private void resetContent()
	{
		_txt.setText("");
	}

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return ForeignExchangeGroup.GetActivityGroupHostControl();
	}

	@Override
	protected H_CODE GetDataFromHttpServer()
	{
		resetContent();
		return HttpAppInfo.SendFXEconomicRequest(actContext, iTypeId, this);
	}

	@Override
	protected void H_UserClient_HttpRequest_Response_Sub(H_UserClient_HttpRequest_Result iResult)
	{
		if (!iResult.MStatus.equals("0"))
		{
			ShowMessageDialog(iResult.MError + "(" + iResult.MStatus + ")");
			return;
		}

		String content = iResult.contentStores.get(0)[0];

		updateData(content);
	}

}
